#
# @lc app=leetcode.cn id=20 lang=python3
#
# [20] 有效的括号
#


# @lc code=start
class Solution:
    def isValid(self, s: str) -> bool:
        d = {'(': ')', '[': ']', '{': '}'}
        length = []
        for char in s:
            if char == '(' or char == '[' or char == '{':
                length.append(char)
            elif length and char == d[length.pop()]:
                continue
            else:
                return False
        if length:
            return False
        else:
            return True


# @lc code=end
